from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-22 14:31:16.317760
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 22, Jan, 2021
Time: 14:31:20
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.3866
Nobs: 179.000 HQIC: -46.3394
Log likelihood: 2009.63 FPE: 3.92000e-21
AIC: -46.9892 Det(Omega_mle): 2.40329e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.437870 0.143824 3.044 0.002
L1.Burgenland 0.134029 0.075702 1.770 0.077
L1.Kärnten -0.233650 0.061474 -3.801 0.000
L1.Niederösterreich 0.126138 0.173976 0.725 0.468
L1.Oberösterreich 0.219847 0.149723 1.468 0.142
L1.Salzburg 0.182356 0.079524 2.293 0.022
L1.Steiermark 0.096411 0.107664 0.895 0.371
L1.Tirol 0.154444 0.072042 2.144 0.032
L1.Vorarlberg 0.014769 0.068687 0.215 0.830
L1.Wien -0.117990 0.144380 -0.817 0.414
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.508370 0.184029 2.762 0.006
L1.Burgenland 0.016192 0.096863 0.167 0.867
L1.Kärnten 0.371182 0.078658 4.719 0.000
L1.Niederösterreich 0.097397 0.222609 0.438 0.662
L1.Oberösterreich -0.168428 0.191577 -0.879 0.379
L1.Salzburg 0.184513 0.101754 1.813 0.070
L1.Steiermark 0.252977 0.137761 1.836 0.066
L1.Tirol 0.139504 0.092181 1.513 0.130
L1.Vorarlberg 0.189183 0.087888 2.153 0.031
L1.Wien -0.577720 0.184740 -3.127 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.303718 0.064336 4.721 0.000
L1.Burgenland 0.113798 0.033863 3.361 0.001
L1.Kärnten -0.024983 0.027499 -0.909 0.364
L1.Niederösterreich 0.045009 0.077824 0.578 0.563
L1.Oberösterreich 0.281349 0.066975 4.201 0.000
L1.Salzburg 0.003748 0.035573 0.105 0.916
L1.Steiermark -0.018092 0.048161 -0.376 0.707
L1.Tirol 0.094201 0.032226 2.923 0.003
L1.Vorarlberg 0.126925 0.030726 4.131 0.000
L1.Wien 0.080346 0.064585 1.244 0.213
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.211627 0.074965 2.823 0.005
L1.Burgenland -0.006406 0.039458 -0.162 0.871
L1.Kärnten 0.023916 0.032042 0.746 0.455
L1.Niederösterreich 0.024295 0.090681 0.268 0.789
L1.Oberösterreich 0.385621 0.078040 4.941 0.000
L1.Salzburg 0.094832 0.041450 2.288 0.022
L1.Steiermark 0.186072 0.056118 3.316 0.001
L1.Tirol 0.044179 0.037551 1.177 0.239
L1.Vorarlberg 0.100979 0.035802 2.821 0.005
L1.Wien -0.067300 0.075255 -0.894 0.371
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.550220 0.149356 3.684 0.000
L1.Burgenland 0.074773 0.078613 0.951 0.342
L1.Kärnten 0.005760 0.063838 0.090 0.928
L1.Niederösterreich -0.033942 0.180667 -0.188 0.851
L1.Oberösterreich 0.132850 0.155482 0.854 0.393
L1.Salzburg 0.050742 0.082583 0.614 0.539
L1.Steiermark 0.123338 0.111805 1.103 0.270
L1.Tirol 0.222276 0.074813 2.971 0.003
L1.Vorarlberg 0.017281 0.071329 0.242 0.809
L1.Wien -0.129468 0.149933 -0.864 0.388
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.154707 0.106427 1.454 0.146
L1.Burgenland -0.019909 0.056018 -0.355 0.722
L1.Kärnten -0.012980 0.045489 -0.285 0.775
L1.Niederösterreich 0.142706 0.128738 1.108 0.268
L1.Oberösterreich 0.384776 0.110792 3.473 0.001
L1.Salzburg -0.026159 0.058846 -0.445 0.657
L1.Steiermark -0.034530 0.079669 -0.433 0.665
L1.Tirol 0.189196 0.053310 3.549 0.000
L1.Vorarlberg 0.047263 0.050827 0.930 0.352
L1.Wien 0.181587 0.106838 1.700 0.089
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.237331 0.134024 1.771 0.077
L1.Burgenland 0.077146 0.070543 1.094 0.274
L1.Kärnten -0.052061 0.057285 -0.909 0.363
L1.Niederösterreich -0.061429 0.162121 -0.379 0.705
L1.Oberösterreich -0.093683 0.139521 -0.671 0.502
L1.Salzburg 0.031156 0.074105 0.420 0.674
L1.Steiermark 0.373970 0.100328 3.727 0.000
L1.Tirol 0.507309 0.067133 7.557 0.000
L1.Vorarlberg 0.195517 0.064007 3.055 0.002
L1.Wien -0.212989 0.134542 -1.583 0.113
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.136930 0.160363 0.854 0.393
L1.Burgenland 0.014042 0.084407 0.166 0.868
L1.Kärnten -0.107933 0.068543 -1.575 0.115
L1.Niederösterreich 0.220990 0.193982 1.139 0.255
L1.Oberösterreich 0.024180 0.166941 0.145 0.885
L1.Salzburg 0.218532 0.088669 2.465 0.014
L1.Steiermark 0.118409 0.120045 0.986 0.324
L1.Tirol 0.098104 0.080327 1.221 0.222
L1.Vorarlberg 0.027209 0.076586 0.355 0.722
L1.Wien 0.261251 0.160983 1.623 0.105
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.580550 0.085856 6.762 0.000
L1.Burgenland -0.020037 0.045190 -0.443 0.657
L1.Kärnten -0.001790 0.036697 -0.049 0.961
L1.Niederösterreich -0.040683 0.103855 -0.392 0.695
L1.Oberösterreich 0.282946 0.089377 3.166 0.002
L1.Salzburg 0.014695 0.047472 0.310 0.757
L1.Steiermark 0.013942 0.064270 0.217 0.828
L1.Tirol 0.073850 0.043005 1.717 0.086
L1.Vorarlberg 0.165784 0.041003 4.043 0.000
L1.Wien -0.065155 0.086187 -0.756 0.450
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.150337 -0.010038 0.213855 0.258012 0.066205 0.080342 -0.068232 0.155504
Kärnten 0.150337 1.000000 0.012817 0.194979 0.160038 -0.113576 0.166268 0.023381 0.313625
Niederösterreich -0.010038 0.012817 1.000000 0.288575 0.081141 0.228244 0.120979 0.052517 0.355110
Oberösterreich 0.213855 0.194979 0.288575 1.000000 0.293058 0.312806 0.087903 0.076532 0.124247
Salzburg 0.258012 0.160038 0.081141 0.293058 1.000000 0.161257 0.068460 0.072119 -0.015470
Steiermark 0.066205 -0.113576 0.228244 0.312806 0.161257 1.000000 0.111446 0.080552 -0.096178
Tirol 0.080342 0.166268 0.120979 0.087903 0.068460 0.111446 1.000000 0.137054 0.138478
Vorarlberg -0.068232 0.023381 0.052517 0.076532 0.072119 0.080552 0.137054 1.000000 0.073362
Wien 0.155504 0.313625 0.355110 0.124247 -0.015470 -0.096178 0.138478 0.073362 1.000000